#include <GameEngine/Graphics/Meshes/BoneSystems/bone_keyframe.h>


#ifdef GAMEENGINE_NAMESPACES
namespace GameEngine {
#endif


//==========================================================================


//! Default constructor
/*!
 *  Time, length and all three arguments are defaulted to 0.
 */
BoneKeyframe::BoneKeyframe() : time_(0.0), length_(0.0) {
	for ( int k = 0; k < 3; ++k ) {
		arguments_[k] = 0.0f;
	}
}

//! Constructor from explicitly given parameters
/*!
 @param time The time at which the keyframe applies
 @param length The length for which the keyframe applies
 @param arg1 The first argument of the keyframe (usually, translation or rotation along the X axis)
 @param arg2 The second argument of the keyframe (usually, translation or rotation along the Y axis)
 @param arg3 The third argument of the keyframe (usually, translation or rotation along the Z axis)
 */
BoneKeyframe::BoneKeyframe(Time::Seconds time, Time::Seconds length, float arg1, float arg2, float arg3) : time_(time), length_(length)
{
	arguments_[0] = arg1;
	arguments_[1] = arg2;
	arguments_[2] = arg3;
}

//! Copy constructor
/*!
 @param rhs The keyframe to copy
 */
BoneKeyframe::BoneKeyframe(const BoneKeyframe& rhs) : time_(rhs.time_), length_(rhs.length_) {
	for ( int k = 0; k < 3; ++k ) {
		arguments_[k] = rhs.arguments_[k];
	}
}

//! Destructor
BoneKeyframe::~BoneKeyframe() {}

//! Assignment operator
/*!
 @param rhs The keyframe to copy
 */
BoneKeyframe& BoneKeyframe::operator=(const BoneKeyframe& rhs) {
	if ( &rhs != this ) {
		time_ = rhs.time_;
		length_ = rhs.length_;
		for ( int k = 0; k < 3; ++k ) {
			arguments_[k] = rhs.arguments_[k];
		}
	}
	return *this;
}

//! Accessor to the time of the keyframe (read only)
/*!
 @return The time at which the keyframe applies
 */
Time::Seconds BoneKeyframe::time() const {
	return time_;
}

//! Accessor to the time of the keyframe (read-write)
/*!
 @return A reference to the time at which the keyframe applies
 */
Time::Seconds& BoneKeyframe::time() {
	return time_;
}

//! Accessor to the length of the keyframe (read only)
/*!
 @return The length for which the keyframe applies
 */
Time::Seconds BoneKeyframe::length() const {
	return length_;
}

//! Accessor to the length of the keyframe (read-write)
/*!
 @return A reference to the length for which the keyframe applies
 */
Time::Seconds& BoneKeyframe::length() {
	return length_;
}

//! Accessor to the argument of the keyframe (read only)
/*!
 @param index The index of the argument to be accessed (First for X axis, Second for Y axis and Third
        for Z axis)
 @return The value of the keyframe argument
 */
float BoneKeyframe::argument(ArgumentIndex index) const {
	return arguments_[(int)index];
}

//! Change the value of the keyframe argument at given index
/*!
 @param index The index of the argument to be changed (First for X axis, Second for Y axis and Third
        for Z axis)
 @param value The new value of the keyframe argument
 */
void BoneKeyframe::set_argument(ArgumentIndex index, float value) {
	arguments_[(int)index] = value;
}

//==========================================================================


#ifdef GAMEENGINE_NAMESPACES
} // namespace GameEngine
#endif
